package com.yjs.ppjokedemo.bean;

import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.databinding.BindingAdapter;
import androidx.recyclerview.widget.DiffUtil;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;

import java.util.Objects;

public class RecomProduct {

    private String name;
    private String imgTou;

    public RecomProduct(String name, String imgTou) {
        this.name = name;
        this.imgTou = imgTou;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getImgTou() {
        return imgTou;
    }

    public void setImgTou(String imgTou) {
        this.imgTou = imgTou;
    }

    @Override
    public String toString() {
        return "RecomProduct{" +
                "name='" + name + '\'' +
                ", imgTou='" + imgTou + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RecomProduct that = (RecomProduct) o;
        return Objects.equals(name, that.name) && Objects.equals(imgTou, that.imgTou);
    }

    public static DiffUtil.ItemCallback<RecomProduct> itemCallback = new DiffUtil.ItemCallback<RecomProduct>() {
        @Override
        public boolean areItemsTheSame(@NonNull RecomProduct oldItem, @NonNull RecomProduct newItem) {
            return oldItem.getName().equals(newItem.getName());
        }

        @Override
        public boolean areContentsTheSame(@NonNull RecomProduct oldItem, @NonNull RecomProduct newItem) {
            return oldItem.equals(newItem);
        }
    };

    @BindingAdapter("app:loadImageRe")
    public static void loadImageRe(ImageView imageView,String imgTou){
        Glide.with(imageView.getContext())
                .load(imgTou)
                .transform(new RoundedCorners(20))
                .into(imageView);
    }

}
